package models

func (db *DbWrapper) GetUserFriendsByCondition(uid int, sex int, zonecode int, relation int) []*UserFriendResult {
	var datas []*UserFriendResult
	sql := db.DbInstance.
		Model(&UserFriend{}).
		Select("user_friends.*, users.nname as nname,users.sex as sex,users.id as uxid,users.headicon as headicon,users.headurl as headurl").
		Joins("left join users on user_friends.uid2 = users.id")

	if zonecode == 0 {
		sql = sql.Where("users.sex=? and users.id=?", sex, uid)
	} else {
		sql = sql.Where("users.sex=? and users.zonecode=? and users.id=?", sex, zonecode, uid)
	}

	if relation == 0 {
		sql = sql.Where("user_friends.relation=0")
	} else {
		sql = sql.Where("user_friends.relation>=1")
	}

	sql.Scan(&datas)
	return datas
}
